package com.huanxing.cloud.pay.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huanxing.cloud.common.core.entity.Result;
import com.huanxing.cloud.pay.api.handler.PayRefundOrderHandler;
import com.huanxing.cloud.pay.api.service.IPayRefundOrderService;
import com.huanxing.cloud.pay.common.dto.CreateRefundsRequest;
import com.huanxing.cloud.pay.common.entity.PayRefundOrder;
import com.huanxing.cloud.security.annotation.HxInner;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/refundorder")
@RequiredArgsConstructor
public class PayRefundOrderController {

	private final Map<String, PayRefundOrderHandler> payRefundOrderHandlerMap;

	private final IPayRefundOrderService payRefundOrderService;

	@HxInner
	@ApiOperation(value = "退款")
	@PostMapping("/refunds")
	public Result refunds(@RequestBody CreateRefundsRequest createRefundsRequest) {
		return payRefundOrderHandlerMap.get(createRefundsRequest.getRefundType()).refund(createRefundsRequest);
	}

	@ApiOperation(value = "通过id查询")
	@SaCheckPermission("payapi:payrefundorder:get")
	@GetMapping("/{id}")
	public Result getById(@PathVariable("id") String id) {
		return Result.success(payRefundOrderService.getById(id));
	}

	@ApiOperation(value = "分页查询")
	@SaCheckPermission("payapi:payrefundorder:page")
	@GetMapping("/page")
	public Result getPage(Page page, PayRefundOrder payRefundOrder) {
		return Result.success(payRefundOrderService.page(page, Wrappers.query(payRefundOrder)));
	}

}
